//
// Created by Zxy on 2021/7/1.
//

#ifndef FACTORY_PRODUCT_H
#define FACTORY_PRODUCT_H

#include <string>
using namespace std;
// 抽象产品类AbstractProduct

class AbstractProduct {
public:
    AbstractProduct() = default;
    virtual ~AbstractProduct() = default;
    // 抽象方法
    virtual void printName() = 0;
    virtual void play() = 0;
};

// 具体产品类 Basketball
class Basketball :public AbstractProduct{
public:
    // 不应在构造函数中调用虚函数
    Basketball() = default;
    ~Basketball() override = default;
    // 具体实现方法
    void printName() override {
        printf("Get Basketball!\n");
    }
    void play() override {
        printf("Play Basketball!\n");
    }
};

// 具体产品类 Football
class Football :public AbstractProduct{
public:
    // 不应在构造函数中调用虚函数
    Football() = default;
    ~Football() override = default;
    // 具体实现方法
    void printName() override {
        printf("Get Football!\n");
    }
    void play() override {
        printf("Play Football!\n");
    }
};

// 具体产品类 Volleyball
class Volleyball :public AbstractProduct{
public:
    // 不应在构造函数中调用虚函数
    Volleyball() = default;
    ~Volleyball() override = default;
    // 具体实现方法
    void printName() override {
        printf("Get Volleyball!\n");
    }
    void play() override {
        printf("Play Volleyball!\n");
    }
};


class Factory{
public:
    AbstractProduct* createProduct(string productName){
        AbstractProduct *pro = nullptr;
        if(productName == "Basketball"){
            pro = new Basketball();
        }
        else if(productName == "Football"){
            pro = new Football();
        }
        else if(productName == "Volleyball"){
            pro = new Volleyball();
        }
        return pro;
    }
};


#endif //FACTORY_PRODUCT_H
